package com.dcd.controller;

import com.dcd.pojo.Collection_information;
import com.dcd.pojo.Follow_car_series;
import com.dcd.service.Collection_informationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Collection_informationController {

    @Autowired
    private Collection_informationService cis;

    /**
     * 根据用户登入id查询咨询收藏
     * @param user_id 用户登入id
     * @return
     */
    @RequestMapping("/select_collection_informationList_byId")
    public List<Collection_information> select_collection_informationList_byId(@RequestParam int user_id){
        return cis.select_collection_informationList(user_id);
    }

    /**
     * 根据类型判断做添加或删除
     * @param collection_information 资讯收藏表对象
     * @param type 类型
     * @return
     */
    @RequestMapping("/insert_or_delete_collection_information")
    public String insert_or_delete_collection_information(@RequestBody Collection_information collection_information,@RequestParam String type){
        if(type.equals("insert")){
            return "{\"result\":\""+cis.add_collection_information(collection_information)+"\"}";
        }
        return "{\"result\":\""+cis.delete_collection_information(collection_information)+"\"}";
    }

    /**
     * 查询用户是否关注指定
     * @param collection_information
     * @return
     */
    @RequestMapping("/select_user_collection_infomation")
    public String select_user_collection_infomation(@RequestBody Collection_information collection_information){
        return "{\"result\":\"" + cis.select_user_collection_infomation(collection_information) + "\"}";
    }
}
